package com.company.behavioral.iterator_pattern.client;

import com.company.behavioral.iterator_pattern.aggregat.AbstractObjectList;
import com.company.behavioral.iterator_pattern.concrete_aggregate.ProductList;
import com.company.behavioral.iterator_pattern.iterator.AbstractIterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Client
 * @Author tiezheng.han
 * @Date 2020/9/4 16:32
 **/
public class Client {
    public static void main(String[] args) {
        List<Object> products = new ArrayList<>();
        products.add("倚天剑");
        products.add("屠龙刀");
        products.add("断肠草");
        products.add("葵花宝典");
        products.add("四十二章经");

        AbstractObjectList list;
        AbstractIterator iterator;
        // 创建聚合对象
        list = new ProductList(products);
        // 常见迭代器对象
        iterator = list.createIterator();

        System.out.println("正向遍历：");
        while (!iterator.isLast()){
            System.out.print(iterator.getNextItem()+ ",");
            iterator.next();
        }
        System.out.println();
        System.out.println("------------------------------");
        System.out.println("逆向遍历：");
        while (!iterator.isFirst()){
            System.out.print(iterator.getPreviousItem() + ",");
            iterator.previous();
        }

    }
}
